﻿using DAL;
using Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
   public class ProductMarager
    {
        ProductService service = new ProductService();
        // 商品
        //新增商品
        public bool AddProduct(Product product) 
        {
            return service.AddProduct(product);
        }
        public List<Product> GetProductCount(string name)
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.Getproducts(name);
            while (reader.Read())
            {
                product = new Product(
                      reader.GetInt32(0),
                    reader.GetString(1),
                     reader.GetInt32(2),
                     reader.GetString(3),
                     reader.GetString(4),
                     reader.GetString(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11),
                     reader.GetString(12),
                     reader.GetDecimal(13),
                     reader.GetInt32(14)

                   );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        public List<Product> GetProductCounts(string name)
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.Getproducts(name);
            while (reader.Read())
            {
                product = new Product(
                      reader.GetInt32(0),
                    reader.GetString(1),
                     reader.GetInt32(2),
                     reader.GetString(3),
                     reader.GetString(4),
                     reader.GetString(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11),
                     reader.GetString(12),
                     reader.GetDecimal(13),
                     reader.GetInt32(14)
                   );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        public List<Product> GetProductCount3(string name)
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.Getproducts3(name);
            while (reader.Read())
            {
                product = new Product(
                    reader.GetInt32(0),
                    reader.GetString(1),
                     reader.GetInt32(2),
                     reader.GetString(3),
                     reader.GetString(4),
                     reader.GetString(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11),
                     reader.GetString(12),
                     reader.GetDecimal(13),
                     reader.GetInt32(14)
                   );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        public List<Product> GetProductCounts2(string name, int stroe, int protype, string proylcd)
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.Getproducts2(name, stroe, protype, proylcd);
            while (reader.Read())
            {
                product = new Product(
                       reader.GetInt32(0),
                    reader.GetString(1),
                     reader.GetInt32(2),
                     reader.GetString(3),
                     reader.GetString(4),
                     reader.GetString(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11),
                     reader.GetString(12),
                     reader.GetDecimal(13),
                     reader.GetInt32(14)
                   );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        //查询产地
        public List<Product> GetProductCount6()
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.Getproduct5();
            while (reader.Read())
            {
                product = new Product(
                     reader.GetString(0)
                      );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        //查询对应ID的商品信息
        public List<Product> SelProduct(string id)
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.SelProduct(id);
            while (reader.Read())
            {
                product = new Product(
                      reader.GetInt32(0),
                    reader.GetString(1),
                     reader.GetInt32(2),
                     reader.GetString(3),
                     reader.GetString(4),
                     reader.GetString(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11),
                     reader.GetString(12),
                     reader.GetDecimal(13),
                     reader.GetInt32(14)
                   );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        //查用户的商品的规格
        public List<Product> SelCartSpeci(string proid)
        {
            List<Product> carts = new List<Product>();
            SqlDataReader reader = service.SelCartSpeci(proid);
            while (reader.Read())
            {
                carts.Add(new Product
                    (
                        reader.GetString(0)//

                        ));

            }
            DBhelper.Close();
            return carts;
        }
        //查询对应店铺的商品
       public List<Product> SelProductByStoreId(string storeId)
        {
            List<Product> carts = new List<Product>();
            SqlDataReader reader = service.SelProductByStoreId(storeId);
            while (reader.Read())
            {
                carts.Add(new Product
                    (
                        reader.GetInt32(0),//id
                        reader.GetString(1),//商品名
                        reader.GetDecimal(2),//商品价格
                        reader.GetString(3)//商品图片
                        ));

            }
            DBhelper.Close();
            return carts;
        }
        //通过商品类型id查询对应的商品
        public List<Product> SelProducByProType(string Protype)
        {
            List<Product> Cailist = new List<Product>();
            Product product = null;
            SqlDataReader reader = service.SelProducByProType(Protype);
            while (reader.Read())
            {
                product = new Product(
                      reader.GetInt32(0),
                    reader.GetString(1),
                     reader.GetInt32(2),
                     reader.GetString(3),
                     reader.GetString(4),
                     reader.GetString(5),
                     reader.GetString(6),
                     reader.GetString(7),
                     reader.GetString(8),
                     reader.GetString(9),
                     reader.GetString(10),
                     reader.GetString(11),
                     reader.GetString(12),
                     reader.GetDecimal(13),
                     reader.GetInt32(14)

                   );
                Cailist.Add(product);
            }
            reader.Close();
            return Cailist;
        }
        
    }
}
